TARGET = das
PORT = /dev/ttyACM0
MEGA = 168p
PROGRAM = avrispv2

DEPEND = $(TARGET).o src/uart.o src/timers.o src/fm.o
DEPEND += src/counter.o src/wow.o src/lcd.o

CC = avr-gcc
CFLAGS = -Wall -Os -mcall-prologues -mmcu=atmega$(MEGA)
OBJ2HEX = avr-objcopy
AVRDUDE = avrdude
DUDEFLAGS = -c $(PROGRAM) -p m$(MEGA) -P $(PORT)
FUSEFLAGS = -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0x01:m

all: upload

upload: $(TARGET).hex
	$(AVRDUDE) $(DUDEFLAGS) -e
	$(AVRDUDE) $(DUDEFLAGS) $(FUSEFLAGS) -U flash:w:$<

%.hex: %.obj
	$(OBJ2HEX) -R .eeprom -O ihex $< $@

%.obj: $(DEPEND)
	$(CC) $(CFLAGS) $(DEPEND) -o $@

$(DEPEND):
